//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.goldcn.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CommonInterceptor implements HandlerInterceptor {

    //private static ApplicationContext applicationContext;

    @Autowired
    RedisTemplate redisTemplate;

    public CommonInterceptor() {
    }

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        SystemContext.setRequest(request);
/*        Map<String,Object> map=SystemContext.getToken();
        String userid=map.get("userId")!=null?map.get("userId").toString():"";
        PrintWriter out = null;
        if (!userid.equals("")){
           Object object= redisTemplate.opsForValue().get(userid);
           if (object==null){
               JSONObject res = new JSONObject();
                res.put("success", false);
                res.put("msg", "登录失效,请重新登录");
                out = response.getWriter();
                out.append(res.toString());
           }
        }*/
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        SystemContext.removeAll();
    }

    /*public static void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }*/


}
